package Module::Changes::Release;

use warnings;
use strict;
use DateTime;
use Perl::Version;


our $VERSION = '0.06';


use base 'Module::Changes::Base';


__PACKAGE__
    ->mk_scalar_accessors(qw(version date author))
    ->mk_array_accessors(qw(changes tags));


# Perl::Version offers ->normal() and ->numify(), but I don't like either for
# Changes, so here is my format.

sub version_as_string {
    my $self = shift;

    # How many fields to show? Don't show a subversion of '0'.
    my @components = $self->version->components;
    $self->version->components(2) if @components == 3 && $components[2] == 0;

    $self->version->_format({
        prefix => '',
        printf => ['%d'],
        extend => '.%02d',
        alpha  => '_%02d',
        suffix => '',
        fields => scalar($self->version->components),
    });
}


sub touch_date {
    my $self = shift;
    $self->date(DateTime->now);
}


sub clone_version {
    my $self = shift;
    Perl::Version->new($self->version);
}


sub remove_tag {
    my ($self, $tag) = @_;
    $self->tags(grep { defined($_) && $_ ne $tag } $self->tags);
}


1;

__END__

{% USE p = PodGenerated %}

=head1 NAME

Module::Changes::Release - a release within a Changes file

=head1 SYNOPSIS

    use Module::Changes;
    my $release = Module::Changes->make_object_for_type('release')
    $release->touch_date;

    $release->date(DateTime::Format::W3CDTF->new->parse_datetime(...));
    print DateTime::Format::Mail->new->format_datetime($release->date);

=head1 DESCRIPTION

This class represents a release within the Changes file. The date is a
L<DateTime> object.

Releases can also have tags. Tags are a way to help other programs understand
(or at least guess) what has happened in each release. Tags are just strings.
See the documentation for the C<changes> program for a discussion of
recommended tags.

=head1 METHODS

=over 4

{% p.write_methods %}

=item version_as_string

    print $release->version_as_string;

Takes the release's version object and returns a string representation.

=item touch_date

    $release->touch_date;

Touch the release's date, setting it to the current date andtime.

=item clone_version

    my $version = $release->clone_version;

Makes a clone of the release's version object. This is useful if you want to
use the version in a new release. You need a clone so you don't inadvertently
change this release's version number as well.

=item remove_tag

    $release->remove_tag('APIBREAK');

Takes a tag name and removes all occurrences of it from the tags array.

=back

{% p.write_inheritance %}

{% PROCESS standard_pod %}

=cut

